package com.hmall.order.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderMessageConfig {

    /**
     * 声明延迟队列
     * @return
     */
    @Bean
    public Queue OrderQueue(){
        return QueueBuilder.durable("order.queue")   //指定队列名称并持久化
                .deadLetterExchange("dl.ttl.exchange")   //指定死信交换机
                .deadLetterRoutingKey("dl")
                .build();
    }

    /**
     * 声明下单交换机
     * @return
     */
    @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange("order.topic");
    }

    /**
     * 声明绑定队列和交换机  ----下单的key
     * @return
     */
    @Bean
    public Binding bingQueue(){
        return BindingBuilder.bind(OrderQueue())
                .to(orderExchange())
                .with("order.create");
    }
}
